<?php


namespace app\admin\controller;


use app\common\controller\AdminController;
use app\admin\model\UserExperience as UserExperienceModel;
use think\Exception;
use think\facade\Request;

class UserExperience extends AdminController {

    protected $levelConfig = [
        1 => ['getlist','editget'],
        2 => ['editpost'],
        4 => [],
        8 => []
    ];

    public $resubmitLock = ['editpost'];

    /**
     * 列表
     * @return false|string
     */
    public function getList() {
        try {
            $params = $this->checkParams('page,long');
            if ($params === false) return $this->resErr();
            $list = UserExperienceModel::getList($params);
            return $this->resData('success', $list);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 编辑获取
     * @return false|string
     */
    public function editGet() {
        try {
            $params = $this->checkParams('id');
            if ($params === false) return $this->resErr();
            $data = UserExperienceModel::where('id', $params['id'])
                ->field('name,mark,status')
                ->find();
            return $this->resData('success', $data);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 编辑提交
     * @return false|string
     */
    public function editPost() {
        try {
            $params = $this->checkParams('status,id');
            if ($params === false) return $this->resErr();
            $res = UserExperienceModel::edit($params);
            if (!$res) return $this->resErr();
            else return $this->resData('编辑成功', []);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

}